/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package sgmi.DAO;

import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Order;
import sgmi.enthy.Departamentos;
import sgmi.enthy.Marcas;
import sgmi.util.HibernateUtil;

/**
 *
 * @author HugoCesar
 */
public class MarcasDAO {
    
    private Session conec;
    private Transaction trans;
    private List<Marcas> list;

    public List<Marcas> getList() {
    
        conec = HibernateUtil.getSessionFactory().openSession();
        trans = conec.beginTransaction();
        
        Criteria cri = conec.createCriteria(Marcas.class);
        cri.addOrder(Order.asc("codMarcas"));
        this.list = cri.list();
    
        return list;
    }
    
     
            
            
    public void addMarcas (Marcas m){
        try{
        
            conec = HibernateUtil.getSessionFactory().openSession();
            trans = conec.beginTransaction();

            Marcas marca= new Marcas();
            marca.setDescricao(m.getDescricao());

            conec.save(marca);
            trans.commit();
        
        } catch(Exception e){
            
            e.printStackTrace();
        
        } finally {
        
        conec.close();
        
        }
    
    
    }
    
    public void removerMarca (Marcas m){
    
         try{
        
            conec = HibernateUtil.getSessionFactory().openSession();
            trans = conec.beginTransaction();

            conec.delete(m);
            trans.commit();
        
        } catch(Exception e){
            
            e.printStackTrace();
        
        } finally {
        
        conec.close();
        
        }
    
    }
    public void updateMarcas (Marcas m){
    
         try{
        
            conec = HibernateUtil.getSessionFactory().openSession();
            trans = conec.beginTransaction();

            conec.update(m);
            trans.commit();
        
        } catch(Exception e){
            
            e.printStackTrace();
        
        } finally {
        
        conec.close();
        
        }
    
    }
}
